/*
 *
编写一个指针函数，实现字符串的拷贝
world
world
world

 */
#include<stdio.h>
#include<assert.h>
char * str_copy(char *dest, const char *src);
char * str_copy2(char *dest, const char *src);
char * str_copy3(char *dest, const char *src);

int main(){
	char s1[100];
	char s2[100];
	char *s3 = "world";
	//三种方案都可达到相同结果，代码越来越简洁
	//str_copy(s1,str_copy(s2,s3));
	//str_copy2(s1,str_copy2(s2,s3));
	str_copy3(s1,str_copy3(s2,s3));
	puts(s1);
	puts(s2);
	puts(s3);

}
char * str_copy(char *dest, const char *src){
	char *s = dest;
	while(*src != '\0'){
		*dest = *src;
		dest++;
		src++;
	}
	*dest = '\0';
	return s;
}

char * str_copy2(char *dest, const char *src){
	char *s = dest;
	while(*src != '\0'){
		*dest++ = *src++;
	}
	*dest = '\0';
	return s;
}
char * str_copy3(char *dest, const char *src){
	assert(dest && src);
	char *s = dest;
	while(*dest++ = *src++);
	return s;
}
